package com.googlecode.continuity.plugin.gwtext.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.googlecode.continuity.plugin.gwtext.client.message.GWTExtensionMessages;

/**
 * ErrorBox
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class ErrorBox extends CenteredDialogBox {

  private final GWTExtensionMessages messages = (GWTExtensionMessages) GWT.create(GWTExtensionMessages.class);

  public ErrorBox(Throwable throwable) {
    this(throwable.getMessage());
  }

  public ErrorBox(String error) {
    setText(messages.error());

    Button close = new Button(messages.close(), finished);
    Label errorMessage = new Label(messages.errorOccured() + error);
    frame.insert(errorMessage, frame.getWidgetIndex(buttons));

    addStyleName("errorBox");
    errorMessage.addStyleName("errorMessage");

    buttons.add(close);

    frame.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
  }
}
